# sample LAMMPS input script for viscosity of 2d LJ liquid
# Einstein form of Green-Kubo

# settings

variable	x equal 20
variable	y equal 20

variable	rho equal 0.6
variable        t equal 1.0
variable	rc equal 2.5

variable    p equal 400     # correlation length
variable    s equal 5       # sample interval
variable    d equal $p*$s   # dump interval 

# problem setup

units		lj
dimension	2
atom_style	atomic
neigh_modify	delay 0 every 1

lattice         sq2 ${rho}
region          simbox block 0 $x 0 $y -0.1 0.1
create_box      1 simbox
create_atoms    1 box

pair_style      lj/cut ${rc}
pair_coeff      * * 1 1

mass            * 1.0
velocity        all create $t 97287

# equilibration run

fix             1 all nve
fix	        2 all langevin $t $t 0.1 498094
fix	        3 all enforce2d

thermo          $d
run	        10000

velocity	all scale $t

unfix		2

# Einstein viscosity calculation

reset_timestep  0

# Define distinct components of symmetric traceless stress tensor

variable         pxy equal pxy
variable         pxx equal pxx-press

fix              avstress all ave/time $s $p $d v_pxy v_pxx ave one &
                 file profile.einstein.2d

# Diagonal components of SS are larger by factor 2-2/d,
# which is 4/3 for d=3, but 1 for d=2.
# See Daivis and Evans, J.Chem.Phys, 100, 541-547 (1994)

variable         scale equal vol/(2.0*$t*dt*$d)
variable         diagfac equal 2-2/2
variable         deltasqxy equal (f_avstress[1]*$d*dt)^2
variable         deltasqxx equal (f_avstress[2]*$d*dt)^2/${diagfac}

# compute mean square displacements as running averages

fix              avdeltasq all ave/time $d 1 $d v_deltasqxy v_deltasqxx ave running

# convert to viscosities

variable         vxy equal f_avdeltasq[1]*${scale}
variable         vxx equal f_avdeltasq[2]*${scale}

thermo_style     custom step temp pe press pxy v_vxy v_vxx

run              500000

variable         etaxy equal v_vxy
variable         etaxx equal v_vxx
variable         eta equal 0.5*(${etaxy}+${etaxx})
print            "running average viscosity: ${eta}"
